#include "MainWindow.h"
#include <QMessageBox>
#include "Messages.h"

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
	Initialize();
}

MainWindow::~MainWindow() {
}

void MainWindow::Initialize() {
	ui.setupUi(this);
    SetCaptionsValues();
    SetSlidersValues();
	ConnectEvents();
}

void MainWindow::SetSlidersValues() {
    ui.sldBlur->setValue(0);
    ui.sldCalibrated->setValue(0);
    ui.sldCamera->setValue(1);
    ui.sldClickSensitivity->setValue(5);
    ui.sldDragSensitivity->setValue(5);
    ui.sldMovementThreshold->setValue(5);
    ui.sldSpeed->setValue(2);
}

void MainWindow::SetCaptionsValues() {
    ui.btnInitialize->setText(BTN_START_CAPTION);
    ui.lblBlur->setText(BLUR_CAPTION);
	ui.lblBlur->adjustSize();
    ui.lblCalibrated->setText(CALIBRATED_CAPTION);
	ui.lblCalibrated->adjustSize();
    ui.lblCamera->setText(CAMERA_CAPTION);
	ui.lblCamera->adjustSize();
    ui.lblClickSensitivity->setText(CLICK_SENSITIVITY_CAPTION);
	ui.lblClickSensitivity->adjustSize();
    ui.lblDragSensitivity->setText(DRAG_SENSITIVITY_CAPTION);
	ui.lblDragSensitivity->adjustSize();
    ui.lblMovementThreshold->setText(MOVEMENT_THRESHOLD_CAPTION);
	ui.lblMovementThreshold->adjustSize();
    ui.lblSpeed->setText(MOUSE_SPEED_CAPTION);
	ui.lblSpeed->adjustSize();
    ui.gbControls->setTitle(CONTROLS_CAPTION);
	this->setWindowTitle(CONFIGURATION_WINDOW_TITLE);
}

void MainWindow::ConnectEvents() {
	connect(ui.sldSpeed, SIGNAL(valueChanged(int)), this, SLOT(OnSpeedSliderValueChanged(int)));
	connect(ui.sldBlur, SIGNAL(valueChanged(int)), this, SLOT(OnBlurSliderValueChanged(int)));
	connect(ui.sldClickSensitivity, SIGNAL(valueChanged(int)), this, SLOT(OnClickSensitivitySliderValueChanged(int)));
	connect(ui.sldDragSensitivity, SIGNAL(valueChanged(int)), this, SLOT(OnDragSensitivitySliderValueChanged(int)));
	connect(ui.sldMovementThreshold, SIGNAL(valueChanged(int)), this, SLOT(OnMovementThresholdSliderValueChanged(int)));
	connect(ui.btnInitialize, SIGNAL(released()), this, SLOT(OnInitializeButtonClicked()));
}

void MainWindow::OnInitializeButtonClicked() {
	tkr_.Execute();
}

void MainWindow::OnSpeedSliderValueChanged(int Value) {
    tkr_.SetMouseSpeed(Value);
}

void MainWindow::OnClickSensitivitySliderValueChanged(int Value) {
	tkr_.SetClickSensitivity(Value);
}

void MainWindow::OnDragSensitivitySliderValueChanged(int Value) {
	tkr_.SetDragSensitivity(Value);
}

void MainWindow::OnMovementThresholdSliderValueChanged(int Value) {
	tkr_.SetMovementTreshold(Value);
}

void MainWindow::OnBlurSliderValueChanged(int Value) {
	tkr_.SetBlurFilterSensitivity(Value);
}